package com.example.demo.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.demo.entity.CodeAssociation;
import com.example.demo.entity.RulesInfo;
import com.example.demo.service.CodeAssociationService;
import com.example.demo.mapper.CodeAssociationMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author 18364
* @description 针对表【code_association】的数据库操作Service实现
* @createDate 2024-10-15 15:16:58
*/
@Service
public class CodeAssociationServiceImpl extends ServiceImpl<CodeAssociationMapper, CodeAssociation>
    implements CodeAssociationService{
    @Autowired
    CodeAssociationMapper codeAssociationMapper;
    @Override
    public CodeAssociation select(String code) {
        QueryWrapper<CodeAssociation> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("codeInfo",code);
        queryWrapper.orderByDesc("id");
        return codeAssociationMapper.selectOne(queryWrapper);
    }

    @Override
    public List<CodeAssociation> selectbyinfo(String code, String userId, String trainingId, String appId) {

        QueryWrapper<CodeAssociation> queryWrapper=new QueryWrapper<>();
        if(code!=null){
            queryWrapper.eq("codeInfo",code);
        }
        if(userId!=null){
            queryWrapper.eq("userId",userId);
        }
        if(trainingId!=null){
            queryWrapper.eq("trainingId",trainingId);
        }
        if(appId!=null){
            queryWrapper.eq("appId",appId);
        }
        queryWrapper.orderByDesc("id");
        return codeAssociationMapper.selectList(queryWrapper);
    }

    @Override
    public Integer delete(String appId, String trainingId, String userId) {
        QueryWrapper<CodeAssociation> queryWrapper=new QueryWrapper<>();
        if(appId!=null){
            queryWrapper.eq("appId",appId);
        }
        queryWrapper.eq("trainingId",trainingId);
        queryWrapper.eq("userId",userId);
        queryWrapper.orderByDesc("id");
        return codeAssociationMapper.delete(queryWrapper);
    }

    @Override
    public List<CodeAssociation> selectByInfo(String userId, String appId, String trainingId) {
        QueryWrapper<CodeAssociation> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("appId",appId);
        queryWrapper.eq("trainingId",trainingId);
        queryWrapper.eq("userId",userId);
        queryWrapper.orderByDesc("id");
        return codeAssociationMapper.selectList(queryWrapper);
    }
}




